package com.example.myBlogTest.mapper;

import cn.hutool.crypto.SecureUtil;
import com.example.myBlogTest.dto.UserRequest;
import com.example.myBlogTest.dto.UserResponse;
import com.example.myBlogTest.entity.User;
import org.springframework.beans.BeanUtils;

/**
 * Author: Lucy
 * Description:
 */
public class UserMapper {

    public static UserResponse convertUserToUserResponse(User foundUser) {
        UserResponse userResponse = new UserResponse();
        BeanUtils.copyProperties(foundUser, userResponse);
        return userResponse;
    }

    public static User convertUserRequestToUser(UserRequest userRequest) {
        User user = new User();
        BeanUtils.copyProperties(userRequest, user);
        user.setPassword(SecureUtil.md5(userRequest.getPassword()));
        return user;
    }
}
